﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Zjs_Shop.Models.Database;


namespace Zjs_Shop.Service
{
    public class Users:IUsers
    {
        private readonly ZjsShopContext _db;
        public Users(ZjsShopContext db)
        {
            _db = db;
        }
        
        public bool Eby(string userName)
        {
            return _db.Users.Any(x =>x.Username == userName);
        }

        public int Reg(string userName,string password)
        {

            var user = new User()
            {
                Username = userName,
               
                Password = password,

            };
            _db.Users.Add(user);
            var row = _db.SaveChanges();
            if (row > 0)
                return user.Id;
            return 0;
        }
    }
}
